<template>
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <el-button class="btn-add" @click="addTag()" size="mini">
        添加
      </el-button>
    </el-card>
    <!-- 表格开始 -->
    <div class="table-container">
      <el-table
        ref="tagTable"
        :data="tagList"
        style="width: 100%"
        element-loading-text="数据加载中"
        v-loading="loading"
        border
      >
        <el-table-column prop="date" label="序号" width="80px">
          <template slot-scope="scope">
            {{ (page - 1) * limit + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="tag" label="标签名称"> </el-table-column>
        <el-table-column prop="gmtCreate" label="创建时间"> </el-table-column>
        <el-table-column prop="gmtModified" label="修改时间"> </el-table-column>
        <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 表格结束 -->

      <!-- 分页开始 -->
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        layout="total,prev, pager, next,jumper"
        @current-change="allTags"
        style="padding: 30px 0; text-align: center"
      >
      </el-pagination>
      <!-- 分页结束 -->
    </div>
  </div>
</template>
<script>
import tags from "@/api/tags";
export default {
  data() {
    return {
      loading: true,
      tagList: null,
      page: 1,
      limit: 10,
      total: 0,
    };
  },
  created() {
    this.allTags();
  },
  methods: {
    allTags() {
      tags.getAllTag().then((res) => {
        this.tagList = res.data.result;
        this.loading = false;
        console.log(res);
      });
    },
    handleDelete(index, row) {
      this.$confirm("是否删除标签", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        tags.delTag(row.id).then((response) => {
          this.$message({
            message: "删除成功",
            type: "success",
            duration: 1000,
          });
          this.allTags();
        });
      });
    },
    addTag(){
      console.log('点击了addTag')
      this.$router.push({path: '/tags/addTag'})
    }
  },
};
</script>
<style lang="sass">
</style>